package com.jyb.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jyb.controller.ApiController;
import com.jyb.controller.CbxxController;
import com.jyb.controller.CqjhController;
import com.jyb.controller.DzxdController;
import com.jyb.controller.GqxhController;
import com.jyb.controller.HgfxController;
import com.jyb.controller.IndexController;
import com.jyb.controller.JxjhController;
import com.jyb.controller.MyOrderController;
import com.jyb.controller.SmsController;
import com.jyb.controller.YpcdController;
import com.jyb.interceptor.UserInterceptor;
import com.jyb.job.CqjhJob;
import com.jyb.job.JxjhJob;
import com.jyb.job.MyOrderJob;
import com.jyb.model.Jxjh;
import com.jyb.model.MyOrder;
import com.jyb.model.QueryLog;
import com.jyb.model.User;
import com.jyb.plugin.QuartzPlugin;

/**
 * API引导式配置
 */
public class JybConfig extends JFinalConfig {
	
	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		// 加载少量必要配置，随后可用getProperty(...)获取值
		loadPropertyFile("config.properties");
		me.setDevMode(getPropertyToBoolean("devMode", false));
	}
	
	/**
	 * 配置路由
	 */
	public void configRoute(Routes me) {
		me.add("/", IndexController.class);
		me.add("/sms",SmsController.class);
		me.add("/cbxx", CbxxController.class);
		me.add("/cqjh", CqjhController.class);
		me.add("/gqxh",GqxhController.class);
		me.add("/hgfx",HgfxController.class);
		me.add("/jxjh",JxjhController.class);
		me.add("/ypcd",YpcdController.class);
		me.add("/myOrder",MyOrderController.class);
		me.add("/dzxd",DzxdController.class);
		me.add("/api",ApiController.class);
	}
	
	/**
	 * 配置插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
		me.add(c3p0Plugin);
		
		//定时任务插件
		QuartzPlugin quartzPlugin=new QuartzPlugin(CqjhJob.class,MyOrderJob.class,JxjhJob.class);
		me.add(quartzPlugin);
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		arp.addMapping("t_user", User.class);	// 映射blog 表到 Blog模型
		arp.addMapping("t_my_order", MyOrder.class);
		arp.addMapping("t_query_log", QueryLog.class);
		arp.addMapping("t_jxjh", Jxjh.class);
		//arp.addMapping("sys_dic_node", DicNode.class);
	}
	
	/**
	 * 配置全局拦截器
	 */
	public void configInterceptor(Interceptors me) {
		me.add(new UserInterceptor());
		//me.add(new ExceptionAndLogInterceptor());
	}
	
	/**
	 * 配置处理器
	 */
	public void configHandler(Handlers me) {
		
	}
	
}
